<template>
  <div class="my-form">
    <div class="add">
      <el-form ref="addF" label-width="200px">
        <el-form-item label="初始密码">
          <el-input v-model="addF.oldpassword" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="最新密码">
          <el-input v-model="addF.newpassword" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="重复最新密码">
          <el-input v-model="addF.chongfu" placeholder="请输入"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div
      style="
        display: flex;
        justify-content: center;
        align-items: center;
        margin-top: 5%;
      "
    >
      <el-button
        type="primary"
        style="width: 100px; height: 40px; font-size: 15px"
        @click="onChange()"
        >修改</el-button
      >
    </div>
  </div>
</template>

<script>
import { EventBus } from "bus/mybus.js";
import { doChangeuserpwd } from "../../crm/mainpage/mainpage";
export default {
  name: "Add",
  data() {
    return {
      addF: {
        oldpassword: "",
        newpassword: "",
        chongfu: "",
      },
    };
  },
  methods: {
    onChange() {
      this.$confirm("确认修改密码?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          const payload = this.addF;
          payload.uid = localStorage.getItem("uid");
          // payload.uid = 1;
          // console.log(payload);
          doChangeuserpwd(payload)
            .then((res) => {
              if (res.data.error_code == 0) {
                this.$message.success("成功");
                this.$router.push("/login");
              } else if (res.data.status == "oldError") {
                this.$message.error("初始密码不正确");
              } else if (res.data.status == "chongError") {
                this.$message.error("重复最新密码不正确");
              }
            })
            .catch((err) => {
              EventBus.$emit("closeloading");
            });
        })
        .catch(() => {});
    },
  },
};
</script>

<style scoped>
.add {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 10%;
}
.el-input {
  width: 300px;
  height: 50px;
}
.el-input /deep/.el-input__inner {
  width: 300px !important;
  height: 50px;
}
.el-select {
  width: 300px !important;
}
.el-form-item {
  margin-left: -2%;
  line-height: 70px;
}
.el-form-item /deep/ .el-form-item__label {
  font-size: 20px;
  margin-top: 5px;
  font-family: SimHei;
  font-weight: 600;
  width: 200px;
}
.el-select /deep/.el-input__inner {
  height: 50px;
}
</style>